package com.geuso.xingdutch.general;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.geuso.xingdutch.R;
import com.geuso.xingdutch.util.SoundUtil;

public class GeneralWordsListAdapter extends ArrayAdapter<GeneralWord>{

	private static final int resource = R.layout.general_word;
	
	public GeneralWordsListAdapter(Context context, ArrayList<GeneralWord> words){
		super(context, resource, words);
	}

	
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		View v = convertView;

		if (v == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(resource, null);
		}
		
		GeneralWord w = getItem(position);
		if (w != null){
			TextView description = (TextView) v.findViewById(R.id.gw_description);
			TextView dutch = (TextView) v.findViewById(R.id.gw_dutch);
			TextView dutch_pronounciation = (TextView) v.findViewById(R.id.gw_dutch_pronounciation);
			ImageView play_sound = (ImageView) v.findViewById(R.id.gw_play_sound);
			
			if (description != null) 			description.setText(w.getDescription());
			if (dutch != null) 					dutch.setText(w.getDutch());
			if (dutch_pronounciation != null) 	dutch_pronounciation.setText(w.getPronounciation());
			
			if (play_sound != null){
				if (w.getSound_file() > 0){
					play_sound.setVisibility(View.VISIBLE);
					SoundUtil.setOnClickPlaySound(play_sound, w.getSound_file());
				}
				else play_sound.setVisibility(View.INVISIBLE);
			}
		}
		return v;
	}
}
